/**
 * @file base.js
 * @description 基础数据相关接口
 * @author YIBOSHEN
 * @date 07-01-2021
 */

import request from '@/utils/request'

/**
 * 项目编码列表
 */
export function getEngagementCode({ pagesize = 10, pagenum = 1, code, category = '' }) {
  return request({
    url: `/v1/engagement_code?pagesize=${pagesize}&pagenum=${pagenum}&code=${code}&category=${category}`,
    method: 'get'
  })
}

/**
 * 新增项目编码
 */
export function addEngagementCode({ engagement_code,
  engagement_code_desc,
  category,
  cc_rate,
  oc_rate,
  department_id,
  code_owner_id,
  team_leader_id,
  hr_id,
  finance_id }) {
  return request({
    url: `/v1/engagement_code`,
    data: {
      engagement_code,
      engagement_code_desc,
      category,
      cc_rate: Number(cc_rate),
      oc_rate: Number(oc_rate),
      department_id,
      code_owner_id,
      team_leader_id,
      hr_id,
      finance_id
    },
    method: 'post'
  })
}

/**
 * 删除项目
 */
export function deleteEngagementCode(id) {
  return request({
    url: `/v1/engagement_code/${id}`,
    method: 'delete'
  })
}

/**
 * 更新项目
 */
export function editEngagementCode({
  id,
  engagement_code,
  engagement_code_desc,
  category,
  cc_rate,
  oc_rate,
  department_id,
  code_owner_id,
  team_leader_id,
  hr_id,
  finance_id
}) {
  return request({
    url: `/v1/engagement_code/${id}`,
    method: 'put',
    data: {
      engagement_code,
      engagement_code_desc,
      category,
      cc_rate: Number(cc_rate),
      oc_rate: Number(oc_rate),
      department_id,
      code_owner_id,
      team_leader_id,
      hr_id,
      finance_id
    }
  })
}

/**
 * 获取部门级别
 */
export function getLevelList({ department_id }) {
  return request({
    url: `v1/level?department_id=${department_id}`,
    method: 'get'
  })
}

/**
 * 获取部门级别
 */
export function addLevel({ department_id, level_name, cc_rate, oc_rate }) {
  return request({
    url: `v1/level`,
    method: 'post',
    data: {
      department_id, level_name, cc_rate: Number(cc_rate), oc_rate: Number(oc_rate)
    }
  })
}

/**
 * 获取部门级别
 */
export function delLevel(id) {
  return request({
    url: `v1/level/${id}`,
    method: 'delete'
  })
}

/**
 * 获取部门级别
 */
export function editLevel({ id, department_id, level_name, cc_rate, oc_rate }) {
  return request({
    url: `v1/level/${id}`,
    method: 'put',
    data: {
      department_id, level_name, cc_rate: Number(cc_rate), oc_rate: Number(oc_rate)
    }
  })
}

/**
 * 获取假期日历
 */
export function getPublicHolidayList({ year, month }) {
  return request({
    url: `v1/public_holiday?year=${year}&month=${month}`,
    method: 'get'
  })
}

/**
 * 创建假期
 */
export function createPublicHolidayList({ holiday_name, public_holiday_date, holiday_type }) {
  return request({
    url: `v1/public_holiday`,
    method: 'post',
    data: {
      holiday_name, public_holiday_date, holiday_type
    }
  })
}

/**
 * 创建假期
 */
export function updatePublicHolidayList({ id, holiday_name, public_holiday_date, holiday_type }) {
  return request({
    url: `v1/public_holiday/${id}`,
    method: 'put',
    data: {
      holiday_name, public_holiday_date, holiday_type
    }
  })
}

/**
 * 新增部门
 */
export function addDepartment({ department_name, department_leader_id }) {
  return request({
    url: `/v1/department`,
    method: 'post',
    data: {
      department_name,
      department_leader_id
    }
  })
}

/**
 * 编辑部门
 */
export function putDepartment({ department_name, department_leader_id, id }) {
  return request({
    url: `/v1/department/${id}`,
    method: 'put',
    data: {
      department_name,
      department_leader_id
    }
  })
}

/**
 * 编辑部门
 */
export function deleteDepartment(id) {
  return request({
    url: `/v1/department/${id}`,
    method: 'delete'
  })
}

/**
 * 服务报价列表
 */
export function projectCategoryList({ pagenum, pagesize }) {
  return request({
    url: `/v1/project_category?pagenum=${pagenum}&pagesize=${pagesize}`,
    method: 'get'
  })
}

/**
 * 新增服务报价
 */
export function addProjectCategory({ project_category_code, service_category_desc, main_service_quotation, sub_service_quotation }) {
  return request({
    url: `/v1/project_category`,
    method: 'post',
    data: {
      project_category_code,
      service_category_desc,
      main_service_quotation: Number(main_service_quotation),
      sub_service_quotation: Number(sub_service_quotation)
    }
  })
}

/**
 * 编辑服务报价
 */
export function putProjectCategory({ project_category_code, service_category_desc, main_service_quotation, sub_service_quotation, id }) {
  return request({
    url: `/v1/project_category/${id}`,
    method: 'put',
    data: {
      project_category_code,
      service_category_desc,
      main_service_quotation: Number(main_service_quotation),
      sub_service_quotation: Number(sub_service_quotation)
    }
  })
}

/**
 * 删除服务报价
 */
export function delProjectCategory(id) {
  return request({
    url: `/v1/project_category/${id}`,
    method: 'delete'
  })
}
